package java1226;

// (1)创建类
public class Student {

    // (2)写成员变量
    String name;
    int age;

    // (3)生成构造方法
    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // (4)生成getter和setter方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // (5)生成toString方法：打印对象信息
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    // (6)main方法创建对象
    public static void main(String[] args) {

        Student s1 = new Student();
        s1.setName("sam");
        s1.setAge(18);
        System.out.println(s1);

        Student s2 = new Student("jack", 16);
        System.out.println(s2);

    }

}
